package org.zhangxiao.paladin2.common.util;

import java.text.ParseException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class LocalDateUtils {

    private static final String defaultFormat = "yyyy-MM-dd";

    public static String toStr(LocalDate dateTime, String pattern) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
        return dateTime.format(formatter);
    }

    public static String toStr(LocalDate date) {
        return toStr(date, defaultFormat);
    }

    public static LocalDate toDateTime(String dateStr, String dateFormat) throws ParseException {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
        return LocalDate.parse(dateStr, formatter);
    }

    public static LocalDate toDateTime(String dateStr) throws ParseException {
        return toDateTime(dateStr, defaultFormat);
    }

}
